<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>灯泡开关</title>
    <style>
        #box{
            text-align: center;
        }
        #btn{
            margin: auto;
            width: 50px;
            height: 50px;
            line-height: 50px;
            background-color: #ddd;
            border-radius: 100%;
            color: #fff;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="box">
        <div id="btn">开</div>
        <img id="img" src="../day02  基础/img/pic_bulboff.gif" />
    </div>

    <script>
        //获取页面dom元素
        var btn = document.querySelector('#btn');
        var img = document.querySelector('#img');

        //通过onclick  绑定 点击事件
        btn.onclick = function(){
            console.log('我被点击了');
            if(this.innerHTML == '开'){
                img.src = '../day02  基础/img/pic_bulbon.gif';
                this.innerHTML = '关';
                this.style.backgroundColor = 'blue';
            }else{
                img.src = '../day02  基础/img/pic_bulboff.gif';
                this.innerHTML = '开';
            }
        }
        
    </script>
</body>
</html>